package com.tinyengine.it.controller.engine.extend;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.model.entity.TPage;
import com.tinyengine.it.model.vo.TPageVo;
import com.tinyengine.it.service.engine.extend.TPageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/app-center/api/extend/page")
@Tag(name = "tiny扩展-page")
public class TpageController {

    @Resource
    TPageService pageService;

    @Operation(summary = "保存sfc")
    @PostMapping("/save/sfc")
    public Result saveSfc(@RequestBody TPageVo pageVo) {

        TPage page = pageService.getById(pageVo.getId());
        if (ObjUtil.isNull(page)) {
            throw new RuntimeException("查询无数据");
        }

        BeanUtil.copyProperties(pageVo,page,"id");

        pageService.updateById(page);

        return Result.success();
    }
    @Operation(summary = "更新PageContent")
    @PostMapping("/updatePageContent")
    public Result updatePageContent(@RequestBody TPageVo pageVo) {

        TPage page = pageService.getById(pageVo.getId());
        if (ObjUtil.isNull(page)) {
            throw new RuntimeException("查询无数据");
        }

        BeanUtil.copyProperties(pageVo,page,"id");

        pageService.updateById(page);

        return Result.success();
    }
}
